package com.ycc.biz.controller;

import com.ycc.biz.pojo.entity.BizAttachment;
import com.ycc.biz.service.BizAttachmentService;
import com.ycc.biz.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 附件Controller
 */
@Api("附件管理")
@RestController
@RequestMapping("/attachment")
@AllArgsConstructor
public class BizAttachmentController {

    private final BizAttachmentService attachmentService;

    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public Result<BizAttachment> uploadFile(
            @ApiParam("文件") @RequestPart MultipartFile file) {
        return Result.success(attachmentService.uploadFile(file));
    }

    @ApiOperation("根据业务ID和业务类型查询附件")
    @GetMapping("/getByBusiness")
    public Result<BizAttachment> getByBusiness(
            @ApiParam("业务ID") @RequestParam String businessId,
            @ApiParam("业务类型") @RequestParam String businessType) {
        return Result.success(attachmentService.getByBusiness(businessId, businessType));
    }

    @ApiOperation("根据业务ID和业务类型查询附件")
    @PostMapping("/getAttachmentById")
    public Result<BizAttachment> getAttachmentById(@ApiParam("id") @RequestParam String id) {
        return Result.success(attachmentService.getById(id));
    }

    @ApiOperation("根据业务ID和业务类型查询附件列表")
    @GetMapping("/listByBusiness")
    public Result<List<BizAttachment>> listByBusiness(
            @ApiParam("业务ID") @RequestParam String businessId,
            @ApiParam("业务类型") @RequestParam String businessType) {
        return Result.success(attachmentService.listByBusiness(businessId, businessType));
    }
} 